import cv2
import pytesseract
from matplotlib import pyplot as plt


# 图片为720p 也就是1080x720
# 读取文件函数
def readImage():
    return cv2.imread('/home/liusen/mount/192.168.1.60_ShareFiles/temp/1.jpg', 0)


# 识别图片函数
def regongizeImage(img):
    return pytesseract.image_to_string(img, lang='eng', config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')


# 展示中间过程函数，方便查看图片切分过程
def showImage(img1, img2, img3, img):
    plt.subplot(221), plt.imshow(img1)
    plt.subplot(222), plt.imshow(img2)
    plt.subplot(223), plt.imshow(img3)
    plt.subplot(224), plt.imshow(img)
    plt.show()


# 需要同学最终编写的代码
img = readImage()
img1 = img[0:720, 0:360]
img2 = img[0:720, 360:720]
img3 = img[0:720, 720:1080]

res = "%s%s%s" % (regongizeImage(img1), regongizeImage(img2), regongizeImage(img3))
print(res)

#结束 中间结果展示
showImage(img1, img2, img3, img)












# image = cv2.imread('/home/liusen/mount/192.168.1.60_ShareFiles/temp/1.jpg', 0)
# img1 = image[0:720, 0:360]
# img2 = image[0:720, 360:720]
# img3 = image[0:720, 720:1080]
#
# res1 = pytesseract.image_to_string(img1, lang='eng', config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
# print(res1)
# res2 = pytesseract.image_to_string(img2, lang='eng', config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
# print(res2)
# res3 = pytesseract.image_to_string(img3, lang='eng', config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
# print(res3)
#
# plt.subplot(221), plt.imshow(img1)
# plt.subplot(222), plt.imshow(img2)
# plt.subplot(223), plt.imshow(img3)
# plt.subplot(224), plt.imshow(image)
# plt.show()
